package com.imageim.yimirror.service.statistic;

import com.imageim.yimirror.base.BaseApplication;
import com.imageim.yimirror.common.network.NetUtil;
import com.imageim.yimirror.common.network.constants.NetConstants;
import com.imageim.yimirror.common.network.listener.NetCallback;
import com.imageim.yimirror.common.network.tool.ParamCreator;
import com.imageim.yimirror.common.util.UserUtil;

import org.apache.http.message.BasicNameValuePair;
import java.util.List;

/**
 * Created by Bruce.Zhou on 2018/8/8 15:39.
 * Email: 907160968@qq.com
 */

public class StatisticServiceImpl implements StatisticService {

    @Override
    public void startPage(String pageId, int pageType) {
        List<BasicNameValuePair> params = new ParamCreator()
                .add("pageType", "" + pageType)
                .add("pageUid", pageId)
                .add("userId", UserUtil.getUserId())
                .add("pageTime", System.currentTimeMillis() + "")
                .add("type", "1").build(); // 1进入
        NetUtil.postObject(BaseApplication.getContext(), NetConstants.URL.REPORT_PAGE_STOP_TIME, params, new NetCallback<String>() {
            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(String result) {
            }

            @Override
            public void onFail(int errorCode, String errorMsg) {
            }
        });
    }

    @Override
    public void endPage(String pageId, int pageType) {
        List<BasicNameValuePair> params = new ParamCreator()
                .add("pageType", "" + pageType)
                .add("pageUid", pageId)
                .add("userId", UserUtil.getUserId())
                .add("pageTime", System.currentTimeMillis() + "")
                .add("type", "2").build(); // 2退出
        NetUtil.postObject(BaseApplication.getContext(), NetConstants.URL.REPORT_PAGE_STOP_TIME, params, new NetCallback<String>() {
            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(String result) {
            }

            @Override
            public void onFail(int errorCode, String errorMsg) {
            }
        });
    }

    @Override
    public void onEvent(int eventId, String... biNos) {
        List<BasicNameValuePair> params = new ParamCreator()
                .add("eventType", "" + eventId)
                .add("eventTime", System.currentTimeMillis() + "")
                .add("userId", UserUtil.getUserId())
                .add("bizNo", (biNos != null && biNos.length > 0) ? biNos[0] : "").build();
        NetUtil.postObject(BaseApplication.getContext(), NetConstants.URL.REPORT_EVENT, params, new NetCallback<String>() {
            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(String result) {
            }

            @Override
            public void onFail(int errorCode, String errorMsg) {
            }
        });
    }
}
